﻿using System;
using System.Collections.Generic;
using System.Text;
using EnvDTE80;
using EnvDTE;
using TSVNAddin.SVN;
using System.IO;

namespace TSVNAddin.Core
{
	public class EventDispatcher
	{
		private readonly SolutionEvents _SolutionEvents;
		private readonly ISolutionEventListener _SolutionEventListener;
		private readonly IProjectEventListener _ProjectEventListener;
		private readonly ProjectItemsEvents _ProjectItemsEvents;
		private readonly IItemEventListener _ItemEventListener;

		public EventDispatcher(SolutionEvents solutionEvents, ISolutionEventListener solutionEventListener, IProjectEventListener projectEventListener, ProjectItemsEvents projectItemsEvents, IItemEventListener itemEventListener)
		{
			_SolutionEvents = solutionEvents;
			_SolutionEvents.Renamed += SolutionRenamed;
			_SolutionEvents.ProjectAdded += ProjectAdded;
			_SolutionEvents.ProjectRemoved += ProjectRemoved;
			_SolutionEvents.ProjectRenamed += ProjectRenamed;

			_SolutionEventListener = solutionEventListener;
			_ProjectEventListener = projectEventListener;

			_ProjectItemsEvents = projectItemsEvents;
			_ProjectItemsEvents.ItemAdded += ItemAdded;
			_ProjectItemsEvents.ItemRemoved += ItemRemoved;
			_ProjectItemsEvents.ItemRenamed += ItemRenamed;

			_ItemEventListener = itemEventListener;
		}

		void SolutionRenamed(string oldName)
		{
			_SolutionEventListener.NotifyRenamed(oldName);
		}

		void ProjectAdded(Project project)
		{
			_ProjectEventListener.NotifyAdded(project);
		}

		void ProjectRemoved(Project project)
		{
			_ProjectEventListener.NotifyRemoved(project);
		}

		void ProjectRenamed(Project project, string oldName)
		{
			_ProjectEventListener.NotifyRenamed(project, oldName);
		}

		void ItemAdded(ProjectItem projectItem)
		{
			_ItemEventListener.NotifyAdded(projectItem);
		}

		void ItemRemoved(ProjectItem projectItem)
		{
			_ItemEventListener.NotifyRemoved(projectItem);
		}

		void ItemRenamed(ProjectItem projectItem, string oldName)
		{
			_ItemEventListener.NotifyRenamed(projectItem, oldName);
		}
	}
}
